import java.awt.Dimension;
import java.awt.Component;
import java.util.HashMap;
import java.util.Iterator;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.*;
import javax.swing.JScrollPane;


public class LOIPanel extends JPanel{
	 public LOIPanel() {
	        JPanel resultPanel = new JPanel();
	        
	        resultPanel.setPreferredSize(new Dimension(1000, 500));
			
	        refreshResults();
			
			add(resultPanel);
	 }
	 public void refreshResults(){
		 Component[] currentComponents = this.getComponents();
		 for(int i=0;i<currentComponents.length;i++){
			 this.remove(currentComponents[i]);
		 }
		 
		 DefaultTableModel tableStruct = new DefaultTableModel();
		// Create a new table instance
		JTable table = new JTable( tableStruct );
		tableStruct.addColumn("Threshold Level #");
		tableStruct.addColumn("Sample State #");
		tableStruct.addColumn("Sample State Detail");
		
		Threshold LOMI=getLevelofMaximumInterest();
		if (SplitSim.thresholds.size()>0){
			for(int runIndex=0;runIndex<LOMI.getStates().size();runIndex++ ){
				tableStruct.addRow(new Object[]{
				"Threshold# "+(int)LOMI.getLevel(),
				runIndex+1,
				LOMI.getState(runIndex)});
			}
		}

		// Add the table to a scrolling pane
		JScrollPane scrollPane = new JScrollPane( table );
		scrollPane.setPreferredSize(new Dimension(900, 400));
		this.add(scrollPane);
		scrollPane.setVisible(true);
		this.setPreferredSize(new Dimension(1000, 500));
	}
	 
	//this function returns the Level of Maximum interest
	public static Threshold getLevelofMaximumInterest(){
		Threshold LOMI = new Threshold(1,0,0);
		if(SplitSim.thresholds.size() >0){
			LOMI = SplitSim.thresholds.get(0);
			for(int runIndex=1;runIndex<SplitSim.thresholds.size();runIndex++ ){
				if (SplitSim.thresholds.get(runIndex).getHitRatio() > LOMI.getHitRatio() || runIndex==1)
				LOMI = SplitSim.thresholds.get(runIndex);
			}
		}
		return LOMI;
	}
}
